<!-- 折叠面板 -->
<template>
  <div class="flex flex-col">
    <div v-for="(item, index) in list" :key="index">
      <div
        class="text-lg/[4rem] font-bold cursor-pointer"
        :class="{ 'text-primary': current === index }"
        @click="onClickTitle(index)"
      >
        {{ item.title }}
      </div>
      <div
        class="collapse-subtitle text-base/[2rem] text-gray-500 pl-3 overflow-hidden"
        :style="{ height: current === index ? '6rem' : 0 }"
      >
        {{ item.subTitle }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, ref } from "vue";
defineProps<{
  list: {
    title: string;
    subTitle: string;
  }[];
}>();

const current = ref(0);

function onClickTitle(index: number) {
  current.value = index;
}
</script>

<style lang="scss" scoped>
.collapse-subtitle {
  transition: height 0.5s ease;
}
</style>
